package com.mlink.vs.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.seasar.struts.annotation.Execute;

import com.google.gson.Gson;
import com.mlink.vs.util.StreamUtil;

public class AppAction {

	/**
	 * request请求对象
	 */
	@Resource
	private HttpServletRequest req;

	/**
	 * response请求对象
	 */
	@Resource
	private HttpServletResponse rep;
	
	//检查更新接口
	@Execute(validator = false)
	public String checkVersion(){
		
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(),Map.class);
		if (mapData == null)
			return null;
		
		String taskId = (String) mapData.get("taskId");
		String taskStatus = (String) mapData.get("taskStatus");
	
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskStatus)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskStatus不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			
			/*PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if(null==piccTaskPool){
				stsMap.put("sts", "1");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}else{
				piccTaskPool.taskStatus=taskStatus;
				String a=piccTaskPool.taskId;
				piccTaskPool.updateTime=new Timestamp((new Date()).getTime());
				piccTaskPoolService.update(piccTaskPool);
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id=UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId=a;
				piccTaskStatus.taskStatus=taskStatus;
				piccTaskStatus.createTime=new Timestamp((new Date()).getTime());
				piccTaskStatusService.insert(piccTaskStatus);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stssMap));
				rep.getWriter().flush();
			}*/
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
}
